import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [
  {
    path:"/",
    redirect:"/login"
  },{
    path:"/login",
    component:()=>import("@/components/login.vue") 
  },{
    path:"/home",
    redirect:"/welcome",
    component:()=>import("@/components/home.vue"),
    children:[
      {
        path:"/welcome",
        component:()=>import("@/components/welcome.vue") 
      },{
        path:"/users",
        component:()=>import("@/components/users/users.vue") 
      }
      ,{
        path:"/roles",
        component:()=>import("@/components/power/roles.vue") 
      }
      ,{
        path:"/rights",
        component:()=>import("@/components/power/rights.vue") 
      },{
        path:"/goods",
        component:()=>import("@/components/goods/goods.vue") 
      }
      ,{
        path:"/params",
        component:()=>import("@/components/goods/params.vue") 
      }
      ,{
        path:"/categories",
        component:()=>import("@/components/goods/categories.vue") 
      }
      ,{
        path:"/orders",
        component:()=>import("@/components/order/order.vue") 
      },{
        path:"/reports",
        component:()=>import("@/components/reports/reports.vue") 
      }
    ]
  }
]

const router = new VueRouter({
  routes
})



// 路由拦截
let token = window.localStorage.getItem("login-token")

router.beforeEach((to,from,next)=>{
  if(!token&&to.path=='/welcome'){
    return next("/login")
  }
  next()
})


export default router
